package cn.zktr.Personnel.model.service.zhouyongcong.end;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.zktr.Personnel.common.TimeStamp;
import cn.zktr.Personnel.model.pojos.PerPmsEmp;
import cn.zktr.Personnel.model.pojos.PerPmsEmpdet;
import cn.zktr.Personnel.model.pojos.PerPmsLxfs;
import cn.zktr.Personnel.model.pojos.PerPmsSex;
import cn.zktr.Personnel.model.service.zhouyongcong.boolService;
import cn.zktr.Personnel.model.service.zhouyongcong.findService;
import cn.zktr.Personnel.model.service.zhouyongcong.saveService;

@Service
@Transactional(rollbackFor=Exception.class)
public class individualService {
	@Autowired
	private findService fs;
	@Autowired
	private saveService ss;
	@Autowired
	private boolService bs;
	
	public void indivfind(Integer id,String text,String zd) {
		System.out.println(text+":"+zd);
		if(zd.equals("name")) {
			PerPmsEmp ppe = fs.findEmpid(id);
			ppe.setEmpname(text);
		}else if(zd.equals("guoji")){
			PerPmsEmpdet pped = fs.findEmpid(id).getPerPmsEmpdets().get(0);
			pped.setDetgj(text);
		}else if(zd.equals("minzu")){
			PerPmsEmpdet pped = fs.findEmpid(id).getPerPmsEmpdets().get(0);
			pped.setDetmz(text);
		}else if(zd.equals("sex")){
			PerPmsEmpdet pped = fs.findEmpid(id).getPerPmsEmpdets().get(0);
			List<PerPmsSex> l_pps = fs.findAllSex();
			for(PerPmsSex pps : l_pps) {
				if(pps.getSexid()==Integer.valueOf(text)) {
					pped.setPerPmsSex(pps);
				}
			}
		}else if(zd.equals("idcare")){
			PerPmsEmp ppe = fs.findEmpid(id);
			ppe.setEmpcard(text);
		}else if(zd.equals("hap")){
			PerPmsEmpdet pped = fs.findEmpid(id).getPerPmsEmpdets().get(0);
			pped.setDetsr(new TimeStamp().valueOf(text));
		}else if(zd.equals("dizi")){
			PerPmsEmpdet pped = fs.findEmpid(id).getPerPmsEmpdets().get(0);
			pped.setDetzz(text);
		}
	}
	public List<PerPmsLxfs> indivfind_lxfs() {
		List<PerPmsLxfs> l_ppl = fs.findAllLxfs();
		List<PerPmsLxfs> l_ppl_2 = new ArrayList<>();
		for(PerPmsLxfs ppl : l_ppl) {
			PerPmsLxfs ppl2 = new PerPmsLxfs();
			ppl2.setLxfs(ppl.getLxfs());
			ppl2.setLxfsid(ppl.getLxfsid());
			l_ppl_2.add(ppl2);
		}
		return l_ppl_2;
	}
	public void indivfind_addlx(Integer empid,String lxfs,String lxxx,Integer lxxxid) {
		if(lxxxid==0) {
			ss.save_Emplx(bs.bool_Emplx()+1,empid, bs.bool_Lxfs(lxfs), lxxx);
		}else {
			ss.save_Emplx(lxxxid,empid, bs.bool_Lxfs(lxfs), lxxx);
		}
		
	}
}
